<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\admin\model;

class User extends \app\BaseModel
{
    protected $name = "user";
    public function __construct()
    {
        parent::__construct();
    }
    public function role()
    {
        return $this->hasOne("Role", "role_id", "role_id");
    }
    public function getUser($filter)
    {
        $user = \think\facade\Db::name($this->name)->where(["deleted" => 0])->where($filter)->find();
        if(isset($user["user_id"])) {
            $user["role"] = \think\facade\Db::name("user_role")->alias("ur")->leftJoin("role role", "ur.role_id = role.role_id")->where(["role.deleted" => 0, "ur.deleted" => 0])->where(["ur.user_id" => $user["user_id"]])->field(["role.role_name", "role.role_id"])->select();
        }
        return $user;
    }
    public function listUserAll($filter)
    {
        $users = \think\facade\Db::name($this->name)->alias("user")->leftJoin("department dp", "user.department_id = dp.department_id")->where(["user.deleted" => 0, "dp.deleted" => 0])->where($filter)->field(["user.*", "dp.department_name"])->select();
        return $users;
    }
    public function listUser($filter, $page_config = ["page" => 1, "page_count" => 10])
    {
        $users = \think\facade\Db::name($this->name)->alias("user")->leftJoin("department dp", "user.department_id = dp.department_id")->where(["user.deleted" => 0, "dp.deleted" => 0])->where($filter)->field(["user.id", "dp.department_name"])->page($page_config["page"], $page_config["page_count"])->select();
        return $users;
    }
    public function listUserCount($filter)
    {
        return $users = \think\facade\Db::name($this->name)->alias("user")->leftJoin("department dp", "user.department_id = dp.department_id")->where(["user.deleted" => 0, "dp.deleted" => 0])->where($filter)->field(["user.id"])->count();
    }
    public function createUser($data)
    {
        return $this->createRow($data);
    }
    public function updateUser($filter, $data)
    {
        return $this->updateRow($filter, $data);
    }
    public function delUser($filter)
    {
        return $this->deleteRow($filter);
    }
}

?>